﻿$userName = "pb";
$to_userName = $userName;
$password = "123";
$address = "127.0.0.1";
$port = "1523";
$sid = "orcl";
$dumpDir = "DATA_MYPUMP_DIR";
$dumpFile = "wssb.DMP";
$schemas = $userName;
$schemas_target = $schemas;
$tablespaceName = $userName;
$datafilePath = "D:\apps\Oracle11\oradata\orcl\$tablespaceName.dbf"; #$datafilePath = "D:\apps\Oracle11\oradata\orcl\$tablespaceName.dbf";

<#

#>
$sqlQuery = @"
		set NewPage none
		set heading off
		set feedback off

		DROP user $userName cascade;

        DROP tablespace $tablespaceName including contents and datafiles;

        CREATE tablespace  $tablespaceName datafile '$datafilePath' size 500M autoextend on next 100M maxsize unlimited logging extent management local autoallocate  segment space management auto;

        CREATE user $to_userName identified by $password default tablespace $tablespaceName temporary tablespace temp;

        GRANT connect,resource,dba to  $to_userName ;

		exit
"@

#$sqlQuery | sqlplus -silent " / as sysdba"
$a ="impdp $userName/$password@${address}:${port}/$sid directory=$dumpDir  dumpfile=$dumpFile fromuser=$userName touser=$to_userName  REMAP_SCHEMA=${schemas}:$schemas_target" ;
#impdp $a

$sqlQuery 
$a